using Spine;
using Spine.Unity;
using System;
using System.Collections;
using UnityEngine;

public static class AnimationExtensions
{
	public static IEnumerator PlayUntilTheEnd(this UnityEngine.Animation animation)
	{
		if (animation != null)
		{
			animation.Play();
			while (animation.isPlaying)
			{
				yield return null;
			}
		}
	}

	public static IEnumerator PlayUntilTheEnd(this UnityEngine.Animation animation, string animationName)
	{
		if (animation != null)
		{
			animation.Play(animationName);
			while (animation.isPlaying)
			{
				yield return null;
			}
		}
	}

	public static void ApplyColor(this SkeletonAnimation animation, Color color)
	{
		animation.skeleton.R = color.r;
		animation.skeleton.G = color.g;
		animation.skeleton.B = color.b;
		animation.skeleton.A = color.a;
	}

	public static void PlayAnimation(this SkeletonAnimation animation, int track, string animationName, bool loop, Action completeCallback)
	{
		animation.state.SetAnimation(track, animationName, loop);
		Spine.AnimationState.TrackEntryDelegate callback = null;
		callback = delegate(TrackEntry trackEntry)
		{
			if (string.Equals(trackEntry.Animation.Name, animationName))
			{
				animation.state.Complete -= callback;
				completeCallback.Fire();
			}
		};
		animation.state.Complete += callback;
	}
}
